#include "Cmn.h"
CButtons::CButtons(){
	day=1;
	Time(_currentDay_,_currentMonth_,_currentYear_);
	month=_currentMonth_;
	year=_currentYear_;
	crossed=false;
	aboutUsCrossedBy=false;
}
void CButtons::paint(CDC& DC,int ButtonSize,int CX,int CY)
{
	_ButtonSize_=ButtonSize;
	_CX_=CX;
	_CY_=CY;
	CBrush TodaysBrushBR(RGB(0, 200, 0));
	char daystr[2];
	itoa(_currentDay_,daystr,10);
	PreStrings();
	//////////////////////////////////////////the date 
	CFont Font1;
	Font1.CreatePointFont(400, "Times New Roman");
	CFont* pOldFont = (CFont*)DC.SelectObject(&Font1);
	char temp[]="kjfgkjfsgjh";
	itoa(year,temp,10);
	DC.TextOut(700, 150, temp);
	using namespace Mon;
	DC.TextOut(680,200,months[month-1]);

	DC.SelectObject(pOldFont);
	///////////////////////////////////////////////////////
	DC.SetTextColor(RGB(0, 0,0 ));
	DC.SetBkMode(TRANSPARENT);
	if(LeftCrossed){
		DC.SetTextColor(RGB(125,125,0));
		DC.TextOutA(CX+10+ButtonSize,CY-41,"<------------------");
		DC.SetTextColor(RGB(0,0,0));
	}
	else if(RightCrossed){
		DC.SetTextColor(RGB(125,125,0));
		DC.TextOutA(CX+10+ButtonSize*4,CY-41,"------------------>");
		DC.SetTextColor(RGB(0,0,0));
	}
	if(crossed){
		CBrush BR(RGB(125, 125, 125));
		CBrush* pOldBR = (CBrush*)DC.SelectObject(&BR);
		DC.FillRect(CRect(XC-2, YC-2, XC+_ButtonSize_-8, YC+_ButtonSize_-8), &BR);
		DC.SelectObject(pOldBR);
	}
	if(clicked){
		CBrush BR(RGB(0, 0, 255));
		CBrush* pOldBR = (CBrush*)DC.SelectObject(&BR);
		DC.FillRect(CRect(XS-2, YS-2, XS+_ButtonSize_-8, YS+_ButtonSize_-8), &BR);
		DC.SelectObject(pOldBR);
	}
	bool startlol=false;
	bool endlol=true;
	char endOfTheMonthStr[3];
	itoa(monthEnd,endOfTheMonthStr,10);
	//DC.SelectStockObject(NULL_BRUSH);
	DC.TextOutA(1+CX+10+ButtonSize,CY-40,"<------------------");
	//DC.Rectangle(CX+10+ButtonSize,CY-15,CX+10+ButtonSize*3,CY+5);
	DC.TextOutA(1+CX+10+ButtonSize*4,CY-40,"------------------>");
	//DC.Rectangle(CX+10+ButtonSize*4,CY-15,CX+10+ButtonSize*6,CY+5);
	using namespace weak;
	SetTextColor(DC,RGB(0,0,150));
	for(int i=0;i<7;i++)
		DC.TextOut(CX+20+i*ButtonSize,CY-20,daysOfWeak[i]);
	SetTextColor(DC,RGB(0,0,0));
	for(int i=0,j=0,x=0;i<42;j++,i++){
		if(j==7)j=0,x++;
		//(pButton+i)->Create(_T(v[i]), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(CX+10+j*ButtonSize,CY+10+x*ButtonSize,CX+ButtonSize+j*ButtonSize,CY+ButtonSize+x*ButtonSize), wnd, i);
		DC.Rectangle(CX+10+j*ButtonSize,CY+10+x*ButtonSize,CX+ButtonSize+j*ButtonSize,CY+ButtonSize+x*ButtonSize);
		DC.TextOut(5+CX+10+j*ButtonSize,5+CY+10+x*ButtonSize,_T(v[i]));
		if (strcmp(v[i],"1")==0)startlol=true;
		else if(strcmp(v[i],endOfTheMonthStr)==0)endlol=false;
		if(strcmp(v[i],daystr)==0&&month==_currentMonth_&&year==_currentYear_&&startlol&&endlol){
			DC.FillRect(CRect(CX+10+j*ButtonSize+2,CY+10+x*ButtonSize+20,CX+ButtonSize+j*ButtonSize-2,CY+ButtonSize+x*ButtonSize-2), &TodaysBrushBR);

		}
	}
	if(aboutUsCrossedBy==true){
		SetTextColor(DC,RGB(200,0,200));
	}
	DC.TextOutA(900,450,"About Us");
}
bool CButtons::OnButtonClicked(int xx,int yy){
	int _day;
	if(xx>_CX_+10+_ButtonSize_&&yy>_CY_-40&&xx<_CX_+10+_ButtonSize_+70&&yy<_CY_-30){
		LeftSelected=true;
		if(--month==0){
			month=12;
			year--;
		}
		return true;
	}
	else LeftSelected=false;
	if(xx>1+_CX_+10+_ButtonSize_*4&&yy>_CY_-80&&xx<_CX_+10+_ButtonSize_*4+70&&yy<_CY_-30){
		RightSelected=true;
		if(++month==13){
			month=1;
			year++;
		}
		return true;
	}
	else RightSelected=false;
	if(xx>_CX_+10&&xx<_CX_+_ButtonSize_*7&&yy>_CY_+10&&yy<_CY_+_ButtonSize_+5*_ButtonSize_){
		for(int i=0,j=0,x=0;i<42;j++,i++){
			if(j==7)j=0,x++;
			if(xx>_CX_+10+j*_ButtonSize_&&xx<_CX_+_ButtonSize_+j*_ButtonSize_&&yy>_CY_+10+x*_ButtonSize_&&yy<_CY_+_ButtonSize_+x*_ButtonSize_){ 
				XS=_CX_+10+j*_ButtonSize_;
				YS=_CY_+10+x*_ButtonSize_;
				//_day=day=atoi(v[i]);
				clicked=true;
				return true;
			}
			else clicked=false;
		}
	}
	else if(xx>900&&yy>450&&xx<950&&yy<500){
		AboutUs Dlg;
		Dlg.DoModal();
	}
}
bool CButtons::CrossingBy(int xx,int yy){
	if(xx>_CX_+10+_ButtonSize_&&yy>_CY_-40&&xx<_CX_+10+_ButtonSize_+70&&yy<_CY_-30){
		LeftCrossed=true;
	}
	else LeftCrossed=false;
	if(xx>1+_CX_+10+_ButtonSize_*4&&yy>_CY_-80&&xx<_CX_+10+_ButtonSize_*4+70&&yy<_CY_-30)RightCrossed=true;
	else RightCrossed=false;
	if(xx>_CX_+10&&xx<_CX_+_ButtonSize_*7&&yy>_CY_+10&&yy<_CY_+_ButtonSize_+5*_ButtonSize_){
		for(int i=0,j=0,x=0;i<42;j++,i++){
			if(j==7)j=0,x++;
			if(xx>_CX_+10+j*_ButtonSize_&&xx<_CX_+_ButtonSize_+j*_ButtonSize_&&yy>_CY_+10+x*_ButtonSize_&&yy<_CY_+_ButtonSize_+x*_ButtonSize_){ 
				XC=_CX_+10+j*_ButtonSize_;
				YC=_CY_+10+x*_ButtonSize_;
				crossed=true;
				return true;
			}
			else crossed=false;
		}
	}
	else if(xx>900&&yy>450&&xx<950&&yy<500)aboutUsCrossedBy=true;
	else {
		crossed =false;
		aboutUsCrossedBy=false;
	}

}
void CButtons::PreStrings(){
	int FS,FSlol;
	int n,nlol;
	char x[5];
	monthAttributesPortable(year,month,&FS,&n);
	monthAttributesPortable(year,month-1,&FSlol,&nlol);
	while(FSlol+7<=nlol)FSlol+=7;
	int i=0;
	monthEnd=n;
	while(FSlol<=nlol){
		itoa(FSlol,v[i],10);
		*(v[i]+2)=0;
		i++;
		FSlol++;
	}
	FSlol=1;
	while(FSlol<=n){
		itoa(FSlol,v[i],10);
		*(v[i]+2)=0;
		i++;
		FSlol++;
	}
	FSlol=1;
	while(i<42){
		itoa(FSlol,v[i],10);
		*(v[i]+2)=0;
		i++;
		FSlol++;
	}
}
CButtons::~CButtons(void)
{
}